<?php

class Plugin_Auth extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        $this->_setViewVars();
    }

    protected function _setViewVars()
    {
        $auth           = Zend_Controller_Action_HelperBroker::getStaticHelper('auth');
        $viewRenderer   = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');

        $viewRenderer->view->isLoggedIn = false;
        $viewRenderer->view->authMember = null;

        if ($auth->isLoggedIn()) {
            $viewRenderer->view->isLoggedIn = true;
            $viewRenderer->view->authMember = $auth->getCurrentMember();
        } else {
            $viewRenderer->view->loginForm = new Form_Login();
        }
    }
}